//
//  EquipmentSelectTableViewCell.h
//  EPBPro
//
//  Created by wucha on 2018/6/21.
//  Copyright © 2018年 fc. All rights reserved.
//

#import "EquipmentSelectTableViewCell.h"

@interface EquipmentSelectTableViewCell()
@property (nonatomic,strong) UILabel *nameLabel;
@property (nonatomic,strong) UIButton *addressButton;
@property (nonatomic,strong) UILabel *timeLabel;
@property (nonatomic,strong) UIImageView *backImageView;
@property (nonatomic,strong) UIButton *selectButton;

@end

@implementation EquipmentSelectTableViewCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = 0;
        UIImageView *backImageView = [UIImageView new];
        [self.contentView addSubview:backImageView];
        backImageView.backgroundColor = HexRGB(0x1991FB);
        backImageView.layer.cornerRadius = 10;
        backImageView.sd_layout.topSpaceToView(self.contentView, 10).bottomSpaceToView(self.contentView, 0).leftSpaceToView(self.contentView, 10).rightSpaceToView(self.contentView, 10);
        self.backImageView = backImageView;
        
        UILabel *nameLabel = [UILabel new];
        nameLabel.font = [UIFont systemFontOfSize:20];
        nameLabel.textColor = [UIColor whiteColor];
        nameLabel.text = @"ATX-1001";
        [backImageView addSubview:nameLabel];
        nameLabel.sd_layout.leftSpaceToView(backImageView, 20).topSpaceToView(backImageView, 15).widthIs(SCREEN_WIDTH-40).heightIs(20);
        self.nameLabel = nameLabel;
        
        UIButton *addressButton = [UIButton new];
        addressButton.titleLabel.font = [UIFont systemFontOfSize:12];
        [addressButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [addressButton setTitle:@"苏州市吴中区穹窿山" forState:UIControlStateNormal];
        [addressButton setImage:[UIImage imageNamed:@"machine_local"] forState:UIControlStateNormal];
        addressButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [backImageView addSubview:addressButton];
        addressButton.sd_layout.leftSpaceToView(backImageView, 20).topSpaceToView(nameLabel, 5).widthIs(SCREEN_WIDTH-40).heightIs(20);
        self.addressButton = addressButton;
        
        UILabel *timeLabel = [UILabel new];
        timeLabel.font = [UIFont systemFontOfSize:12];
        timeLabel.textColor = [UIColor whiteColor];
        timeLabel.text = @"2018/1/1-2022//1/1";
        [backImageView addSubview:timeLabel];
        timeLabel.sd_layout.leftSpaceToView(backImageView, 20).topSpaceToView(addressButton, 0).widthIs(SCREEN_WIDTH-40).heightIs(20);
        self.timeLabel = timeLabel;
        
        UIButton *selectButton = [UIButton new];
        [selectButton setImage:[UIImage imageNamed:@"unselected"] forState:UIControlStateNormal];
        [selectButton setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateSelected];
        [backImageView addSubview:selectButton];
        self.selectButton = selectButton;
        selectButton.sd_layout.topSpaceToView(backImageView, 0).rightSpaceToView(backImageView, 10).widthIs(20).bottomSpaceToView(backImageView, 0);
//        UIImageView *arrowImageView = [UIImageView new];
//        arrowImageView.image = [UIImage imageNamed:@"machine_arrow"];
//        arrowImageView.contentMode = UIViewContentModeCenter;
//        [backImageView addSubview:arrowImageView];
//        arrowImageView.sd_layout.topSpaceToView(backImageView, 0).rightSpaceToView(backImageView, 10).widthIs(11).bottomSpaceToView(backImageView, 0);
        
    }
    
    return self;
}

-(void)setMachineInfo:(EquipmentInfo*)equipmentInfo{
    self.nameLabel.text = equipmentInfo.code;
    [self.addressButton setTitle:[NSString stringWithFormat:@"%@%@",equipmentInfo.city,equipmentInfo.district] forState:UIControlStateNormal];
    if ([equipmentInfo.status isEqualToString:@"open"]) {
        self.timeLabel.hidden = YES;
        self.backImageView.backgroundColor = DefaultOpenColor;
        self.addressButton.sd_layout.topSpaceToView(self.nameLabel,10);
        [self.addressButton updateLayout];
    }else if([equipmentInfo.status isEqualToString:@"renting"]){
        self.timeLabel.hidden = NO;
        self.backImageView.backgroundColor = DefaultTenantColor;
        self.timeLabel.text = [NSString stringWithFormat:@"%@到%@",equipmentInfo.rentStartDate,equipmentInfo.rentEndDate];
        
    }else{
        self.backImageView.backgroundColor = DefaultRepairColor;
        
    }
    
    if (equipmentInfo.isClick) {
        self.selectButton.selected = YES;
    }else{
        self.selectButton.selected = NO;

    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end

